package com.kinghood.productcenter.common.utils;

import com.kinghood.infrastructure.api.authority.UserRemoteVo;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.Objects;

/**
 * 用户名工具
 *
 * @author jp
 * @date 2024/01/04
 */
public class UserNameUtil {

    public static String getName(Long userId, Map<Long, UserRemoteVo> userMap) {
        if (Objects.isNull(userMap)) {
            return null;
        }
        UserRemoteVo user = userMap.get(userId);
        if (Objects.nonNull(user)) {
            String realName = user.getRealName();
            String username = user.getUsername();
            if (StringUtils.isNotBlank(realName)) {
                return realName + "/" + username;
            }
            return username;
        }
        return null;
    }
}
